//
//  RPSecureMobileModel.m
//  RPCFCADemo_Example
//
//  Created by john on 2022/11/5.
//  Copyright © 2022 john. All rights reserved.
//

#import "RPSecureMobileModel.h"

@implementation RPSecureMobileModel
- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic
{
    self.isSuccess = self.code == 0;
        
//    NSString * messageEncrypt  =  [[GMUtils hexToData:[GMSm4Utils cbcEncryptData:self.e key:[GMUtils stringToHex:sm4Prikey] IV:[GMUtils stringToHex:@"abcdefghABCDEFGH"]]];
    
//    NSString * messageDecrypt = [[GMUtils base64Encode: [GMSm4Utils cbcDecryptText:self.e key:[GMUtils stringToHex:sm4Prikey] IV:[GMUtils stringToHex:@"abcdefghABCDEFGH"]]];
    
//        NSString * messageDecrypt =  [GMUtils hexToData:];
    
    
//   NSString *result =  [GMSm4Utils cbcDecryptData:[GMUtils base64Decode:self.e] key:[GMUtils stringToHex:sm4Prikey] IV:[GMUtils stringToHex:@"abcdefghABCDEFGH"]];
    
//    NSString *messageEncrypt = @"hozlzp5aytfWbzZzIP2JjOCV2lmNzP4jAeW37RV/+W+9SxG+DhuEPZkkkLYE04YrnCM7l1E78ZtJ8sXMvQuRo0DJUKOb0pQ68vlAeT/U05N01VFPcP2kyRTD7Was9mZOeYatwA5G+5WhqshSPg+MP7D4J9AeJzNTzeJtz4laWM1u3CG56ZDXIxchi5LzTt8sGulYGi6F2+MwgTvO4ZQ69HRWq7Kcl7wMZ5bgTRJbsv0=";
//    NSData *data = [GMUtils base64Decode:messageEncrypt];
    if(!self.e.isNotBlank){
        self.error = [NSError errorWithDomain:@"ddd" code:10000 userInfo:@{@"NSLocalizedDescriptionKey":self.msg}];
        return YES;
    }
    NSData *data = [GMUtils base64Decode:self.e];
    NSString *data1  = [GMUtils dataToHex:data];
    NSString *sm4Prikey = @"BB310F6B74408F3B";
    NSString *result = [GMSm4Utils cbcDecryptText:data1 key:[GMUtils stringToHex:sm4Prikey] IV:[GMUtils stringToHex:@"abcdefghABCDEFGH"]];
    self.result = result;
    
    NSDictionary *resultDict = result.mj_JSONObject;
    self.user_name = resultDict[@"user_name"];
    self.login_time = resultDict[@"login_time"];
    self.wait_flag = resultDict[@"wait_flag"];
    self.user_token = resultDict[@"user_token"];

    if (self.isSuccess) {
        self.error = [NSError errorWithDomain:@"ddd" code:10000 userInfo:@{@"NSLocalizedDescriptionKey":@"错误"}];
    }
    return YES;
}
@end
